﻿using System;
using System.Collections.Generic;
using System.Text;
using ArlesInterfaces.Editor;

namespace Arles.src.controller
{
    public class LimitedStack<T>
    {
        public List<T> elements;

        public LimitedStack(int capacity)
        {
            elements = new List<T>();
            elements.Capacity = capacity;
        }

        public int Count()
        {
            return elements.Count;
        }

        public void Push(T newElement)
        {
            if (elements.Count == elements.Capacity)
                elements.RemoveAt(elements.Count - 1);

            elements.Insert(0, newElement);
        }

        public T Peek()
        {
            return elements[0];
        }

        public T Pop()
        {
            T elem = elements[0];
            elements.RemoveAt(0);
            return elem;
        }

        public void Clear()
        {
            elements.Clear();
        }

        public string toString()
        {
            String result = String.Empty;
            foreach (ICommand c in elements)
                result += " " + c.toString();

            return result;
        }
    }
}
